$(document).ready(function() {
	$("#loginButton").click(function() {
		var json = {
			"username" : $("#username").val(),
			"password" : $("#password").val(),
			"rememberme" : "false",
		};
		$('input[name="RM"]:checked').each(function() {
			json.rememberme = "true";
		});
		$.ajax({
			url : '/admin/login',
			type : "POST",
			data : JSON.stringify(json), //转JSON字符串  
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(info) {
				$("#result").html(info.message);
				if (info.message.indexOf("login success") != -1) {
					window.location.href = "index.jsp";
				} else if (info.message.indexOf("Unauthorized") != -1) {
					alert("未授权!");
				}
			},
			error : function(info) {
				alert(JSON.stringify(info))
			}
		});
	});
});


function loginFunction() {

	// 校验用户名:
	// 获得用户名文本框的值:
	var username = document.getElementById("username").value;
	if (username == null || username == '') {
		alert("用户名不能为空!");
		return false;
	}
	// 校验密码:
	// 获得密码框的值:
	var password = document.getElementById("password").value;
	if (password == null || password == '') {
		alert("密码不能为空!");
		return false;
	}
	
	// 校验验证码:
	// 获得验证码:
	var verificationCode = document.getElementById("verificationCode").value;
	if (verificationCode == null || verificationCode == '') {
		alert("验证码不能为空!");
		return false;
	}

	$.post('/schsystem/admin/login', {
		"username" : $("#username").val(),
		"password" : $("#password").val(),
		"verificationCode" : $("#verificationCode").val()
	}, function(data, textStatus) {
		if (textStatus == "success") {
			
		} else {
			alert("登录 异常 ");
		}
	}, "json");
	
}